package com.source.myatguigu;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author wengqy
 * @Date 2021/1/12
 */
public class VailtateDemo {
    public static void main(String[] args) {
        Resource  resource = new Resource();
        for (int i = 1; i <= 2000; i++) {
            new Thread(resource).start();
        }

        System.out.println(resource.getNum());
        System.out.println(resource.getAtomicInteger().get());

    }
}

class  Resource implements  Runnable{

    private   int  num =0;
    private AtomicInteger  atomicInteger  = new AtomicInteger(0);

    public AtomicInteger getAtomicInteger() {
        return atomicInteger;
    }

    public void setAtomicInteger(AtomicInteger atomicInteger) {
        this.atomicInteger = atomicInteger;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }



    @Override
    public void run() {
        atomicInteger.incrementAndGet();
        num ++;
    }
}
